package org.example;

public class Student2 implements Comparable<Student2> {
    private String name;
    private int age;
    private double chinses;
    private double math;
    private double english;
    //重写toString方法
    @Override
    public String toString() {
        return "Student2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", chinses=" + chinses +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    public Student2() {
    }

    public Student2(String name, int age, double chinses, double math, double english) {
        this.name = name;
        this.age = age;
        this.chinses = chinses;
        this.math = math;
        this.english = english;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getChinses() {
        return chinses;
    }

    public void setChinses(double chinses) {
        this.chinses = chinses;
    }

    public double getMath() {
        return math;
    }

    public void setMath(double math) {
        this.math = math;
    }

    public double getEnglish() {
        return english;
    }

    public void setEnglish(double english) {
        this.english = english;
    }

    @Override
    public int compareTo(Student2 o) {
        double sum1=this.chinses+this.math+this.english;
        double sum2=o.chinses+o.math+o.english;

        int i= (int) (sum1-sum2);
         i= i==0? (int) (this.chinses - o.chinses) :i;
         i= i==0? (int) (this.math - o.math) :i;
         i= i==0? (int) (this.english - o.english) :i;
         i= i==0?(int)(this.getName().compareTo(o.getName())):i;
        return i;
    }
}
